package com.foreverwin.jzymes.production.picking.service.impl;


import com.alibaba.fastjson.JSONObject;
import com.foreverwin.jzymes.common.constant.Constants;
import com.foreverwin.jzymes.common.service.*;
import com.foreverwin.jzymes.common.util.BOHandleUtil;
import com.foreverwin.jzymes.common.util.CommonMethods;
import com.foreverwin.jzymes.framework.exception.BusinessException;
import com.foreverwin.jzymes.framework.util.DateUtil;
import com.foreverwin.jzymes.framework.util.I18nUtil;
import com.foreverwin.jzymes.framework.util.ObjectMapperUtil;
import com.foreverwin.jzymes.production.picking.domain.PickingBillLog;
import com.foreverwin.jzymes.production.picking.domain.PickingBom;
import com.foreverwin.jzymes.production.picking.enums.PickingstatusEnum;
import com.foreverwin.jzymes.production.picking.mapper.PickingBomMapper;
import com.foreverwin.jzymes.production.picking.mapper.PickingMapper;
import com.foreverwin.jzymes.production.picking.service.IPickingAdviceService;
import com.foreverwin.jzymes.production.picking.service.IPickingBillLogService;
import com.foreverwin.jzymes.production.picking.service.IPickingBomService;
import com.foreverwin.jzymes.production.picking.wsdl.*;
import com.foreverwin.jzymes.production.sfc.domain.SFC;
import com.foreverwin.jzymes.production.sfc.service.ISFCService;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PickingAdviceServiceImpl implements IPickingAdviceService {
    @Autowired
    ISiteAdviceService siteAdviceService;
    @Autowired
    IPickingBillLogService pickingBillLogService;
    @Autowired
    IPickingBomService pickingBomService;
    @Autowired
    PickingBomMapper pickingBomMapper;
    @Autowired
    PickingMapper pickingMapper;
    @Autowired
    ISFCService isfcService;
    @Autowired
    IFieldGroupAdviceService fieldGroupAdviceService;
    @Autowired
    IItemAdviceService itemAdviceService;
    @Autowired
    IItemGroupAdviceService iItemGroupAdviceService;
    @Autowired
    ICustomFieldsAdviceService customFieldsAdviceService;
    @Autowired
    ICommonService commonService;
    @Autowired
    ISystemRuleAdviceService systemRuleAdviceService;

    public String RKPF_BWART;
    public String URL;
    public String oaPlant;
    public String RKPF_KOSTL;

    @Value( "${mes.wsdl.pickItem}" )
    private String pickItemWsdlUrl;

    /**
     * 保存领料单据信息
     *
     * @param jsonMap
     */
    @Transactional( propagation = Propagation.REQUIRED, rollbackFor = Exception.class )
    public void insertPicking( Map<String,Object> jsonMap ) {
        /**检验领料单录入字段*/
        checkPicking( jsonMap );

        String site = (String) jsonMap.get("site");
        String status = (String) jsonMap.get("status");
        String machineType = (String)jsonMap.get("machineType");
        String pickOperation = (String)jsonMap.get("pickOperation");
        String bill = getBillNumber( site );
        //String bill  = "20190711A";
        jsonMap.put("bill",bill);

        /**领料单据补充字段*/
        String hand = BOHandleUtil.buildPickingBillLogHandle( site , bill );

        PickingBillLog  pickingBill = new  PickingBillLog();
        pickingBill.setHandle( hand );
        pickingBill.setSite( site );
        pickingBill.setBill( bill );
        pickingBill.setSfc( (String)jsonMap.get("sfc") );
        pickingBill.setStatus( status );
        pickingBill.setCreatedDateTime( new Date());
        pickingBill.setCreateUserBo( ( String ) jsonMap.get( "createUserBo" ) );
        pickingBill.setMachineType( machineType );
        pickingBill.setPickOperation( pickOperation );

        pickingBillLogService.insertPickingBillLog( pickingBill );

        List< Map< String,Object > > mapList = (List< Map< String,Object > >) jsonMap.get("bomlist");
        List< PickingBom > pickingList = ObjectMapperUtil.convertList( mapList , PickingBom.class );

        for( PickingBom  picking : pickingList ){
                /**检查物料*/
                itemAdviceService.existItem( site , picking.getItem() );
                /**填充字段*/
                picking.setSite( site );
                picking.setOrderBo( hand );
                picking.setCreatedDateTime( new Date() );
                String BO = BOHandleUtil.buildPickingBomHandle( site , hand , picking.getItem(), picking.getCreatedDateTime());
                picking.setHandle( BO );

                pickingBomService.insertPickingBom( picking );
            }
    }

    /**
     * 更新领料单据信息
     *
     * @param jsonMap
     */
    @Override
    public void updatePicking(Map<String, Object> jsonMap) {
        /**检查字段*/
       checkPicking( jsonMap );

       String site = (String)jsonMap.get("site") ;
       String bill = (String)jsonMap.get("bill");
       String handle = BOHandleUtil.buildPickingBillLogHandle( CommonMethods.getSite() , bill );
       PickingBillLog pickingBillLog = pickingBillLogService.selectPickingBillLogById( handle );
       /**验证领料单*/
       Assert.notNull(pickingBillLog , I18nUtil.getI18nText("production.picking.BillNo",new String []{ bill }));

       pickingBillLog.setSfc( (String)jsonMap.get("sfc") );
       pickingBillLog.setMachineType( (String)jsonMap.get("machineType") );
       pickingBillLog.setPickOperation( (String)jsonMap.get("pickOperation") );
       pickingBillLogService.updatePickingBillLog( pickingBillLog );

       List< PickingBom > pickingBoms  = pickingBomService.selectBomList( handle );
        /**验证领料单明细*/
        Assert.notNull( pickingBoms , I18nUtil.getI18nText("production.picking.BillNo",new String []{ bill }));

        pickingMapper.deletePickingByBillBo( handle );

        List< Map< String,Object > > mapList = (List< Map< String,Object > >) jsonMap.get("bomlist");
        List< PickingBom > pickingList = ObjectMapperUtil.convertList( mapList , PickingBom.class );

        for( PickingBom  picking : pickingList ){
            /**检查物料*/
            itemAdviceService.existItem( site , picking.getItem() );
            /**填充字段*/
            picking.setSite( site );
            picking.setOrderBo( handle );
            picking.setCreatedDateTime( new Date() );
            String BO = BOHandleUtil.buildPickingBomHandle( site , handle , picking.getItem(), picking.getCreatedDateTime());
            picking.setHandle( BO );

            pickingBomService.insertPickingBom( picking );
        }


    }

    /**
     * 自动生成领料单编号
     *
     * @return
     */
    public   String  getBillNumber( String  site ){

        String pickingNumberRule = systemRuleAdviceService.existSystemRule( site, Constants.SYSTEM_RULE_PICKING_NUMBER_RULE);

        String orderNo = commonService.generateOrderNo( site , pickingNumberRule );

        return orderNo;
    }

    /**
     * 检索领料单
     *
     * @param jsonMap
     * @return
     * */
    @Override
    public Map<String,Object> selectPicking(Map<String, Object> jsonMap) {

        String site = (String) jsonMap.get("site");
        String bill = (String) jsonMap.get("bill");
        /**单据号不能为空*/
        Assert.hasText( bill,I18nUtil.getI18nText("production.picking.Bill" ) );
        /**领料单号是否存在*/
        String handle =  BOHandleUtil.buildPickingBillLogHandle( site , bill);
        PickingBillLog pickingBillLog = pickingBillLogService.selectPickingBillLogById( handle );
        Assert.notNull( pickingBillLog , I18nUtil.getI18nText("production.picking.BillNo", new String[]{ bill }));

        Map< String ,Object > returnMap = new HashMap< String ,Object >();
        List< PickingBom > bomList = pickingBomService.selectBomList( handle );
        String sfc = pickingBillLog.getSfc();
        if ( sfc != "" && sfc != null){
          SFC sfc1  = isfcService.selectSFCById( BOHandleUtil.buildSFCHandle( site , sfc ) );
          returnMap.put("sfcQty",sfc1.getSfcQty());
        }
        returnMap.put( "bill" , bill );
        returnMap.put( "status", pickingBillLog.getStatus() );
        returnMap.put( "sfc", sfc );
        returnMap.put( "machineType" ,pickingBillLog.getMachineType());
        returnMap.put( "pickOperation" ,pickingBillLog.getPickOperation());
        returnMap.put( "bomlist",bomList );

        return returnMap;
    }

    /**
     * 领料单传OA
     *
     * @param jsonMap
     */
    @Transactional( propagation = Propagation.REQUIRED, rollbackFor = Exception.class )
    public void sendPicking( Map<String, Object> jsonMap ) {
        String site = ( String ) jsonMap.get("site");
        String bill = ( String ) jsonMap.get("bill");

        /**加载系统规则*/
        preload(site);

        /**领料单号是否存在*/
        String handle =  BOHandleUtil.buildPickingBillLogHandle( site , bill );
        PickingBillLog pickingBillLog =  pickingBillLogService.selectPickingBillLogById( handle );
        Assert.notNull( pickingBillLog , I18nUtil.getI18nText("production.picking.BillNo", new String[]{ bill }));
        String device = pickingBillLog.getMachineType() ;
        String operation = pickingBillLog.getPickOperation();

        /**检查领料单状态*/
        Assert.isTrue( PickingstatusEnum.NEW == PickingstatusEnum.valueOf( pickingBillLog.getStatus() ) , I18nUtil.getI18nText( "production.picking.PickingStatusNEW" , new String[]{ ( String ) jsonMap.get("bill") } ) );
        /**获取物料清单list*/
        List< PickingBom > pickingList = pickingBomService.selectBomList( handle );

        /**送签人员*/
         String creator = CommonMethods.getUserBo().split(",")[1];
         //String creator = "Y0012220";
         String id = exchangeUserId( creator );
         if ( StringUtils.isBlank( id ) ){
             throw BusinessException.build("production.picking.ExchangeFail",new String[]{ creator });
         }

        /**调OAwebservice*/
        String requestId = sendOAisSuccess( pickingList ,site ,bill ,device ,id ,operation);

        /**领料单创建失败*/
        if ( Integer.valueOf( requestId ) < 0 ){
           throw BusinessException.build( "production.picking.Fail" , new String[] { bill , requestId } );
        }

        if ( StringUtils.isEmpty( requestId ) ){

            /**失败再调方法*/
            String Y = sendOAisSuccess( pickingList ,site ,bill , device ,id , operation);

            /**返回值为空情况特殊需要查找OA日志*/
            if ( StringUtils.isEmpty( Y ) ){
                throw BusinessException.build( "production.picking.requestId" , new String [] { ( String ) jsonMap.get("bill") });
            }else {

                pickingBillLog.setRequestId( Y );
                pickingBillLog.setStatus( PickingstatusEnum.SIGN.name() );
                pickingBillLog.setUpdatedDateTime( new Date() );
                pickingBillLog.setUpdateUserBo( CommonMethods.getUserBo() );
                pickingBillLogService.updatePickingBillLog( pickingBillLog );
            }

        }else {

            pickingBillLog.setRequestId( requestId );
            pickingBillLog.setStatus( PickingstatusEnum.SIGN.name() );
            pickingBillLog.setUpdatedDateTime( new Date() );
            pickingBillLog.setUpdateUserBo( CommonMethods.getUserBo() );
            pickingBillLogService.updatePickingBillLog( pickingBillLog );
        }
    }

    /**
     * 加载系统规则
     *
     * @param site
     */
    public void preload( String site ){

        /**获取系统规则*/
        URL = systemRuleAdviceService.existSystemRule( site, Constants.SYSTEM_RULE_EXCHANGE_USER_ID );

        /**获取系统规则领料单移动类型*/
        RKPF_BWART = systemRuleAdviceService.existSystemRule( site, Constants.PICKING_RKPF_BWART );

        /**获取系统规则领料工厂*/
        oaPlant = systemRuleAdviceService.existSystemRule( site, Constants.SYSTEM_RULE_ERP_PLANT );

        /**获取系统规则成本中心*/
        RKPF_KOSTL = systemRuleAdviceService.existSystemRule( site, Constants.PICKING_RKPF_KOSTL );

    }

    /**传送OA是否成功*/
    public  String  sendOAisSuccess( List< PickingBom > pickingList ,String site ,String bill,String device,String creator,String operation){
        /**站点在使用机种*/
        //String machineType = iItemGroupAdviceService.findItemGroupBySite( site );

        /**工序*/
        /*Map<String,Object> objectMap = iItemGroupAdviceService.existItemGroup( site , machineType );
        String itemGroupBo = (String) objectMap.get("HANDLE");
        String operation = customFieldsAdviceService.existCustomValue( itemGroupBo , Constants.ITEM_GROUP_PICKING_OPERATION);*/

        /**移动类型*/
        //String RKPF_BWART =  systemRuleAdviceService.findSystemRule( site , Constants.PICKING_RKPF_BWART );

        /**领料工厂*/
       // String oaPlant = systemRuleAdviceService.existSystemRule( site, Constants.SYSTEM_RULE_ERP_PLANT );

        /**成本中心*/
       // String RKPF_KOSTL = systemRuleAdviceService.findSystemRule( site, Constants.PICKING_RKPF_KOSTL );
       // "JZY10003"

        /**送签人员*/
       // String creator = CommonMethods.getUserBo().split(",")[1];
       //   String creator = "40";

        ArrayOfWorkflowRequestTableField tableFieldArray = new ArrayOfWorkflowRequestTableField();
        /**申请人*/
        WorkflowRequestTableField wrti = new WorkflowRequestTableField();
        wrti.setFieldName( "sqr" );
        wrti.setFieldValue( creator );
        wrti.setView( true );
        wrti.setEdit( true );
        tableFieldArray.getWorkflowRequestTableField().add( wrti );

        /**申请日期*/
        wrti = new WorkflowRequestTableField();
        wrti.setFieldName( "sqrq" );
        wrti.setFieldValue( DateUtil.format( new Date(), "yyyy-MM-dd" ) );
        wrti.setView( true );
        wrti.setEdit( true );
        tableFieldArray.getWorkflowRequestTableField().add( wrti );

        /**数据来源*/
        wrti = new WorkflowRequestTableField();
        wrti.setFieldName( "ZSOURCE" );
        wrti.setFieldValue( "ME" );
        wrti.setView( true );
        wrti.setEdit( true );
        tableFieldArray.getWorkflowRequestTableField().add( wrti );

        /**ME单号*/
        wrti = new WorkflowRequestTableField();
        wrti.setFieldName( "RKPF_RESUM" );
        wrti.setFieldValue( bill );
        wrti.setView( true );
        wrti.setEdit( true );
        tableFieldArray.getWorkflowRequestTableField().add( wrti );

        /**移动类型*/
        wrti = new WorkflowRequestTableField();
        wrti.setFieldName( "RKPF_BWART" );
        wrti.setFieldValue( RKPF_BWART );
        wrti.setView( true );
        wrti.setEdit( true );
        tableFieldArray.getWorkflowRequestTableField().add( wrti );

        /**成本中心*/
        wrti = new WorkflowRequestTableField();
        wrti.setFieldName( "RKPF_KOSTL" );
        wrti.setFieldValue( RKPF_KOSTL );
        wrti.setView( true );
        wrti.setEdit( true );
        tableFieldArray.getWorkflowRequestTableField().add( wrti );

        /**工厂*/
        wrti = new WorkflowRequestTableField();
        wrti.setFieldName( "RKPF_WERKS" );
        wrti.setFieldValue( oaPlant );
        wrti.setView( true );
        wrti.setEdit( true );
        tableFieldArray.getWorkflowRequestTableField().add( wrti );

        /**基准日期*/
        wrti = new WorkflowRequestTableField();
        wrti.setFieldName( "RKPF_RSDAT" );
        wrti.setFieldValue( DateUtil.format( new Date(), "yyyy-MM-dd" ) );
        wrti.setView( true );
        wrti.setEdit( true );
        tableFieldArray.getWorkflowRequestTableField().add( wrti );

        /**主表*/
        WorkflowRequestTableRecord wrtri = new WorkflowRequestTableRecord();
        wrtri.setWorkflowRequestTableFields( tableFieldArray );
        ArrayOfWorkflowRequestTableRecord tableRecordArray = new ArrayOfWorkflowRequestTableRecord();
        tableRecordArray.getWorkflowRequestTableRecord().add( wrtri );
        WorkflowMainTableInfo wmi = new WorkflowMainTableInfo();
        wmi.setRequestRecords( tableRecordArray );


        /**领料明细表*/
        ArrayOfWorkflowRequestTableRecord detailTableRecords = new ArrayOfWorkflowRequestTableRecord();
        int i = 1;
        for ( PickingBom  picking : pickingList  ){
            /**检查物料*/
            itemAdviceService.existItem( site  , picking.getItem() );
            /**第一行*/
            WorkflowRequestTableRecord tableRecord = new WorkflowRequestTableRecord();
            ArrayOfWorkflowRequestTableField rowFields = new ArrayOfWorkflowRequestTableField();
            tableRecord.setWorkflowRequestTableFields( rowFields );

            /**明细表行项目*/
            WorkflowRequestTableField rowField = new WorkflowRequestTableField();
            rowField.setFieldName( "RESB_RSPOS" );
            String str = String.valueOf( i );
            int j = str.length();
            if ( j == 1 ){
                rowField.setFieldValue( "00"+ str );
            }else if ( j == 2 ){
                rowField.setFieldValue( "0"+str );
            }else if ( j == 3 ){
                rowField.setFieldValue( str );
            }
            rowField.setView( true );
            rowField.setEdit( true );
            rowFields.getWorkflowRequestTableField().add( rowField );
            i++;

            /**明细表预留凭证*/
            rowField = new WorkflowRequestTableField();
            rowField.setFieldName( "RKPF_RESUM" );
            rowField.setFieldValue( bill );
            rowField.setView( true );
            rowField.setEdit( true );
            rowFields.getWorkflowRequestTableField().add( rowField );
            /**明细表工令*/
            rowField = new WorkflowRequestTableField();
            rowField.setFieldName( "RESB_SGTXT" );
            rowField.setFieldValue( picking.getRemark() );
            rowField.setView( true );
            rowField.setEdit( true );
            rowFields.getWorkflowRequestTableField().add( rowField );
            /**明细表物料编号*/
            rowField = new WorkflowRequestTableField();
            rowField.setFieldName( "RESB_MATNR" );
            rowField.setFieldValue( picking.getItem() );
            rowField.setView( true );
            rowField.setEdit( true );
            rowFields.getWorkflowRequestTableField().add( rowField );
            /**明细表物料描述*/
            rowField = new WorkflowRequestTableField();
            rowField.setFieldName( "MAKT_MATKX" );
            rowField.setFieldValue( picking.getDescription() );
            rowField.setView( true );
            rowField.setEdit( true );
            rowFields.getWorkflowRequestTableField().add( rowField );
            /**明细表数量*/
            rowField = new WorkflowRequestTableField();
            rowField.setFieldName( "RESB_MENGE" );
            rowField.setFieldValue( String.valueOf( picking.getQty() ) );
            rowField.setView( true );
            rowField.setEdit( true );
            rowFields.getWorkflowRequestTableField().add( rowField );
            tableRecord.setWorkflowRequestTableFields( rowFields );
            /**明细表单位*/
            rowField = new WorkflowRequestTableField();
            rowField.setFieldName( "RESB_MEINS" );
            rowField.setFieldValue( picking.getUnit() );
            rowField.setView( true );
            rowField.setEdit( true );
            rowFields.getWorkflowRequestTableField().add( rowField );
            tableRecord.setWorkflowRequestTableFields( rowFields );
            /**明细表机种*/
            rowField = new WorkflowRequestTableField();
            rowField.setFieldName("RESB_WEMPF");
            rowField.setFieldValue( device );
            rowField.setView( true );
            rowField.setEdit( true );
            rowFields.getWorkflowRequestTableField().add( rowField );
            tableRecord.setWorkflowRequestTableFields( rowFields );
            /**明细表领料工序*/
            rowField = new WorkflowRequestTableField();
            rowField.setFieldName("RESB_ABLAD");
            rowField.setFieldValue( operation );
            rowField.setView( true );
            rowField.setEdit( true );
            rowFields.getWorkflowRequestTableField().add( rowField );
            tableRecord.setWorkflowRequestTableFields( rowFields );

            /**添加第一行*/
            detailTableRecords.getWorkflowRequestTableRecord().add( tableRecord );

        }


        /**设置明细表行*/
        WorkflowDetailTableInfo detailTableInfo = new WorkflowDetailTableInfo();
        detailTableInfo.setWorkflowRequestTableRecords( detailTableRecords );
        /**添加明细表*/
        ArrayOfWorkflowDetailTableInfo detailTables = new ArrayOfWorkflowDetailTableInfo();
        detailTables.getWorkflowDetailTableInfo().add( detailTableInfo );

        /**流程id*/
        WorkflowBaseInfo wbi = new WorkflowBaseInfo();
        wbi.setWorkflowId( "353" );

        WorkflowRequestInfo workflowRequestInfo = new WorkflowRequestInfo();
        /**创建人*/
        workflowRequestInfo.setCreatorId( creator );
        workflowRequestInfo.setRequestLevel( "2" );
        workflowRequestInfo.setRequestName( DateUtil.format( new Date(), "yyyy-MM-dd" ) + "MES领料单据"+ bill );
        workflowRequestInfo.setWorkflowBaseInfo( wbi );
        workflowRequestInfo.setWorkflowMainTableInfo( wmi );
        workflowRequestInfo.setWorkflowDetailTableInfos( detailTables );

        URL url = null;
        try {
            url = new URL( pickItemWsdlUrl );
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        WorkflowService workflowService = new WorkflowService( url );
        WorkflowServicePortType portType = workflowService.getWorkflowServiceHttpPort();
        String requestId =  portType.doCreateWorkflowRequest( workflowRequestInfo, 111 );

        return  requestId;
    }


    /**检验领料单录入字段*/
    public void checkPicking( Map<String,Object> dataMap ){
        /**检验站点*/
        siteAdviceService.existSite( (String)dataMap.get( "site" ) );
        /**检查领料单状态*/
        Assert.hasText( (String)dataMap.get( "status" ),I18nUtil.getI18nText("production.picking.Status" ) );

        /**工令不必须*/
        if (  !StringUtils.isBlank( (String)dataMap.get( "sfc" ) ) ){

            String handle = BOHandleUtil.buildSFCHandle( (String)dataMap.get( "site" ) , (String)dataMap.get( "sfc" ) );
            SFC sfc_ = isfcService.selectSFCById( handle );
            Assert.notNull( sfc_,I18nUtil.getI18nText("production.sfc.sfcNotExist", new String[]{ (String)dataMap.get( "sfc" ) }) );
            //String status = "StatusBO:"+(String)dataMap.get( "site" )+",401";
            /**检查工令状态*/
            /*if ( !sfc_.getStatusBo().equals( status )  ){
                throw BusinessException.build("production.picking.sfcStatus",new String[]{ sfc_.getSfc(),sfc_.getStatusBo() });
            }*/
            /**工令已经创建领料单*/
            /*PickingBillLog pickingBillLog = pickingMapper.selectPickingBySfc( (String)dataMap.get( "sfc" ) , (String)dataMap.get( "site" ) );
            Assert.isNull( pickingBillLog ,I18nUtil.getI18nText("production.picking.SfcIsExsited",new String[]{ (String)dataMap.get( "sfc" ) ,pickingBillLog.getBill() } ) ); */

           }

        /**物料清单不能为空*/
        List< Map< String,Object > > mapList = (List< Map< String,Object > >) dataMap.get("bomlist");
        Assert.isTrue( mapList != null && mapList.size() > 0, I18nUtil.getI18nText( "production.picking.Bomlist" ) );
        /**检查机种类型*/
        fieldGroupAdviceService.existFieldGroup( (String)dataMap.get( "site" ),Constants.FIELD_GROUP_PICKING_MACHINE_TYPE,(String)dataMap.get( "machineType" )  );
        /**检查领料工序*/
        //Assert.hasText( (String)dataMap.get( "pickOperation" ),I18nUtil.getI18nText("production.picking.pickOperationISnull" ) );
        fieldGroupAdviceService.existFieldGroup( (String)dataMap.get( "site" ),Constants.ITEM_GROUP_CUSTOM_FIELD_PICK_OPERATION,(String)dataMap.get( "pickOperation" )  );

    }
    /**
     * 转换编号
     *
     * @param
     */
    public String exchangeUserId(String employee){
       try{
           String number = URLEncoder.encode( employee , "utf-8");
           String apiUrl = URL +  number ;

           URL url= new URL(apiUrl);
           URLConnection open = url.openConnection();
           InputStream input = open.getInputStream();
           String response = IOUtils.toString(input,"utf-8");

           Map<String ,Object> map =(Map) JSONObject.parse(response);
           String id = (String) map.get("id");

           return id;
       }catch ( Exception e ){
         throw  BusinessException.build( e.getMessage() );
       }

    }
}
